home *** CD-ROM | disk | FTP | other *** search
/ Software Explosion / Software Explosion (Fore-Matt Home Computing)(1996).iso / games / workbench / labyrinth_ii / mod2.c < prev    next >
C/C++ Source or Header  |  1988-10-04  |  15KB  |  653 lines

  1.  
  2. #define MODE_OLDFILE 1005L    /* System define, easier than using the whole
  3.                              * include file */
  4. #define BOYS 24        /* Number of boys in game */
  5. #define GIRLS 24    /* (sex distinction so program can print right pronoun) */
  6. #define STUDENTS BOYS+GIRLS
  7. #define MEN 18
  8. #define WOMEN 4
  9. #define TEACHERS MEN+WOMEN
  10. #define PLAYERS STUDENTS+TEACHERS
  11. #define OBJECTS 44
  12. #define VERBS 38
  13. #define FAWEAPON 7    /* First offensive weapon */
  14. #define FDWEAPON 2    /* First defensive weapon */
  15. #define FTREASURE 31    /* First valuable object */
  16. #define AWEAPONS 24    /* Number of offensive weapons */
  17. #define DWEAPONS 5    /* Number of defensive weapons */
  18. #define TREASURES 14    /* Number of valuable objects */
  19. #define ROOMS 217
  20. #define NAMELEN 30L        /* Max length of user-defined name */
  21. #define INLEN 60L        /* Max length of input */
  22. #define DESCLEN 40000L     /* Amount of memory space for location descriptions */
  23. #define NOWHERE -9999    /* If something is NOWHERE, it no longer exists */
  24. #define MAXCARR 10        /* Maximum number of objects that can be carried */
  25. #define DROPZONE 75        /* Where treasures must be dropped to score points */
  26.  
  27. long openmouth (),Open (),Read (),RangeRand (),start (),checkinput (),input ();
  28. int lockable (),walk (),numobj ();
  29.  
  30. #define rnd(x) RangeRand((long)x)
  31. #define MAX(a,b) ((a)>(b)?(a):(b))
  32. #define MIN(a,b) ((a)<(b)?(a):(b))
  33.  
  34. typedef char flag;    /* For a very small range of possible values */
  35.  
  36. extern char *directions[],*oname[],*verb[],*pname[];
  37. extern int defval[],attval[],value[],ownroom[];
  38.  
  39. extern flag talking;
  40. extern flag violence;        /* Tame or gruesome */
  41. extern flag descriptions;    /* 0 for brief to 2 for verbose */
  42. extern flag narration;        /* 0/1 ... local/global */
  43. extern int player;            /* Who is the player? */
  44.  
  45. extern int score[PLAYERS+1];    /* +1 is because we're not using element 0 */
  46. extern int strength[PLAYERS+1];
  47. extern int power[PLAYERS+1];
  48. extern int ploc[PLAYERS+1];    /* Location of player */
  49. extern int pcouldbe[PLAYERS+1];    /* For deciding which is one named in input */
  50.  
  51. extern int oloc[OBJECTS+1];    /* Location of object */
  52. extern int ocouldbe[OBJECTS+1];
  53.  
  54. extern int exits[ROOMS+1][10];    /* Exits from rooms */
  55. extern int oexits[ROOMS+1][10];    /* Original exits from rooms */
  56. extern flag visited[ROOMS+1];    /* Which rooms have been visited */
  57.  
  58. extern int Verb,Noun;            /* Verb,noun input by player */
  59. extern int oldverb,oldnoun;    /* Previous verb, noun */
  60. extern int gameover;            /* Is game over? */
  61. extern long waiting;            /* How many turns still to wait? */
  62. extern long filehandle;        /* Handle for room description file */
  63. extern char namebuf[NAMELEN];    /* buffer for user-defined name */
  64. extern char inbuf[INLEN];        /* buffer for input */
  65. extern char *descs;            /* Location of room description file in memory */
  66. extern char *shortdesc[ROOMS+1],*longdesc[ROOMS+1];    /* Location of descriptions */
  67.  
  68. int doinput ()
  69. {
  70.     int i,j,k;
  71.     char *a;
  72.     if (Verb>3 && Verb<14)    /* A direction */
  73.     {
  74.         i=walk (player,Verb-4);
  75.         if (i==1)
  76.             print ("The door's locked.\n");
  77.         if (i==2 && Verb<12)
  78.             print ("You can't go that way.\n");
  79.         if (i==2 && Verb==12)
  80.             print ("You seem to have got a bit out of practice at the levitation lately.\n");
  81.         if (i==2 && Verb==13)
  82.             print ("There seems to be a big hard flat thing called the ground in the way.\n");
  83.         if (i==0)                    /* Successful! */
  84.             look (ploc[player]);    /* so describe new location */
  85.         return (0);    /* Anyway, return to main program */
  86.     }
  87.     switch (Verb)
  88.     {
  89.         case (2):    /* Open */
  90.             if (oloc[1]!=-player)
  91.             {
  92.                 print ("You can't open anything without keys!\n");
  93.                 return (1);
  94.             }
  95.             for (i=0;i<=9;i++)
  96.                 if (exits[ploc[player]][i]<0)
  97.                 {
  98.                     print ("The door opens to the ");
  99.                     print (directions[i]);
  100.                     exits[ploc[player]][i]=-exits[ploc[player]][i];
  101.                     for (j=0;j<=9;j++)
  102.                         if (exits[exits[ploc[player]][i]][j]==-ploc[player])
  103.                             exits[exits[ploc[player]][i]][j]=ploc[player];
  104.                     return (0);
  105.                 }
  106.             print ("There's no locked door here to open.\n");
  107.             return (1);
  108.         case (3):    /* Close */
  109.             if (oloc[1]!=-player)
  110.             {
  111.                 print ("You can't close anything without keys!\n");
  112.                 return (1);
  113.             }
  114.             for (i=0;i<=9;i++)
  115.                 if (oexits[ploc[player]][i]<0 && exits[ploc[player]][i]>0)
  116.                 {
  117.                     print ("You close and lock the door.\n");
  118.                     for (j=0;j<=9;j++)
  119.                         if (exits[exits[ploc[player]][i]][j]==ploc[player])
  120.                             exits[exits[ploc[player]][i]][j]=-ploc[player];
  121.                     exits[ploc[player]][i]=-exits[ploc[player]][i];
  122.                     return (0);
  123.                 }
  124.             print ("I see no open door here which may be locked.\n");
  125.             return (1);
  126.         case (16):    /* Kill */
  127.             if (Noun==0)
  128.             {
  129.                 print ("You have to enter the name of a player you wish to attack.\n");
  130.                 return (1);
  131.             }
  132.             if (ploc[Noun]!=ploc[player])
  133.             {
  134.                 print (pname[Noun]);
  135.                 print (" isn't here.\n");
  136.                 return (1);
  137.             }
  138.             if (Noun==player)
  139.             {
  140.                 print ("Suicide is not the answer!\n");
  141.                 return (1);
  142.             }
  143.             j=40;
  144.             k=0;
  145.             for (i=0;i<AWEAPONS;i++)
  146.                 if (attval[i]>j && oloc[i+FAWEAPON]==-player)
  147.                 {
  148.                     j=attval[i];
  149.                     k=i+FAWEAPON;
  150.                 }
  151.             print ("You attack ");
  152.             print (pname[Noun]);
  153.             if (k)
  154.             {
  155.                 print (" with ");
  156.                 oprint (k,0);
  157.             }
  158.             print (".\n");
  159.             for (k=0;k<DWEAPONS;k++)
  160.                 if (oloc[k+FDWEAPON]==-Noun)
  161.                     j-=defval[k];
  162.             strength[Noun]-=j;
  163.             if (strength[Noun]<1)
  164.             {
  165.                 ploc[Noun]=NOWHERE;
  166.                 power[player]+=(power[Noun]/4);
  167.                 if (violence)
  168.                 {
  169.                     switch (rnd(4))
  170.                     {
  171.                         case (0):
  172.                             print ("With one well-placed blow, you cleave ");
  173.                             print (pname[Noun]);
  174.                             print ("'s skull. Pinkish-grey brain tissue spatters all over the walls.\n");
  175.                             break;
  176.                         case (1):
  177.                             print ("You get past your exhausted enemy's guard and sever the carotid artery. A bright red stream of ");
  178.                             print ("blood spurts out, drenching the room.\n");
  179.                             break;
  180.                         case (2):
  181.                             print ("Your attack succeeds in slicing open ");
  182.                             print (pname[Noun]);
  183.                             print ("'s belly. A pile of steaming guts spills out onto the floor.\n");
  184.                             break;
  185.                         case (3):
  186.                             print ("You lop ");
  187.                             print (pname[Noun]);
  188.                             print ("'s head clean off. It bounces to the floor and the decapitated corpse collapses, jetting a");
  189.                             print (" stream of blood from the stump of the neck.\n");
  190.                     }
  191.                 }
  192.                     else
  193.                     {
  194.                         print (pname[Noun]);
  195.                         print (" dies.\n");
  196.                     }
  197.                 for (i=1;i<=OBJECTS;i++)
  198.                     if (oloc[i]==-Noun)
  199.                     {
  200.                         oloc[i]=ploc[player];
  201.                         oprint (i,1);
  202.                         print (" falls to the ground.\n");
  203.                     }
  204.             }
  205.             break;
  206.         case (18):    /* Take */
  207.             if (Noun==0)
  208.             {
  209.                 print ("I don't understand what you're referring to.\n");
  210.                 return (1);
  211.             }
  212.             if (oloc[Noun]==-player)
  213.             {
  214.                 print ("You already have the ");
  215.                 print (oname[Noun]);
  216.                 print (".\n");
  217.                 return (1);
  218.             }
  219.             if (oloc[Noun]!=ploc[player])
  220.             {
  221.                 print ("I don't see any ");
  222.                 print (oname[Noun]);
  223.                 print (" here.\n");
  224.                 return (1);
  225.             }
  226.             if (numobj (-player)>=MAXCARR)
  227.                 print ("You can't carry any more.\n");
  228.                     else
  229.                     {
  230.                         print ("Taken.\n");
  231.                         oloc[Noun]=-player;
  232.                     }
  233.             break;
  234.         case (19):    /* Drop */
  235.             if (Noun==0)
  236.             {
  237.                 print ("I don't understand what you want to drop.\n");
  238.                 return (1);
  239.             }
  240.             if (oloc[Noun]!=-player)
  241.             {
  242.                 print ("You're not holding any ");
  243.                 print (oname[Noun]);
  244.                 print (".\n");
  245.                 return (1);
  246.             }
  247.             if (ploc[player]==DROPZONE && Noun>=FTREASURE && Noun<FTREASURE+TREASURES)
  248.             {
  249.                 print ("The ");
  250.                 print (oname[Noun]);
  251.                 print (" vanishes in a swirl of light and your score is incremented by ");
  252.                 printshort (value[Noun-FTREASURE]);
  253.                 print (" points.\n");
  254.                 score[player]+=value[Noun-FTREASURE];
  255.                 oloc[Noun]=NOWHERE;
  256.             }
  257.                 else
  258.                 {
  259.                     print ("Dropped.\n");
  260.                     oloc[Noun]=ploc[player];
  261.                 }
  262.             break;
  263.         case (20):    /* Wait */
  264.             if (Noun)
  265.                 waiting=Noun-1;
  266.                     else
  267.                         waiting=0;
  268.             break;
  269.         case (21):    /* Spectator */
  270.             waiting=2000000000;
  271.             print ("Entering spectator mode. Press any key to stop.\n");
  272.             break;
  273.         case (22):    /* Quit */
  274.             print ("Are you sure you want to stop playing? (Y/N)");
  275.             if (yesno ())
  276.                 gameover=1;
  277.             break;
  278.         case (23):    /* Look */
  279.             i=descriptions;
  280.             descriptions=2;
  281.             look (ploc[player]);
  282.             descriptions=i;
  283.             break;
  284.         case (24):    /* Inventory */
  285.             print ("You are ");
  286.             print (pname[player]);
  287.             print (".\n");
  288.             print ("Your power is ");
  289.             printshort (power[player]);
  290.             print (".\n");
  291.             print ("Your strength is ");
  292.             printshort (strength[player]);
  293.             print (".\n");
  294.             print ("Your score is ");
  295.             printshort (score[player]);
  296.             print (".\n");
  297.             if (numobj (-player)==0)
  298.                 print ("You are emptyhanded.\n");
  299.                     else
  300.                     {
  301.                         print ("You are carrying ");
  302.                         olist (-player);
  303.                     }
  304.             break;
  305.         case (25):    /* Who */
  306.             j=0;
  307.             print ("The following players are still around:");
  308.             for (i=1;i<=PLAYERS;i++)
  309.                 if (ploc[i]!=NOWHERE && i!=player)
  310.                 {
  311.                     a=inbuf;
  312.                     if (j)
  313.                         *a++=',';
  314.                     *a++=' ';
  315.                     for (k=0;pname[i][k]!='\0';k++)
  316.                         a[k]=pname[i][k];
  317.                     a[k++]='\0';
  318.                     print (inbuf);
  319.                     j=1;
  320.                 }
  321.             print (".\n");
  322.             break;
  323.         case (26):    /* Information */
  324.             print ("The following players are still around:\n");
  325.             for (i=1;i<=PLAYERS;i++)
  326.                 if (ploc[i]!=NOWHERE && i!=player)
  327.                 {
  328.                     a=pname[i];
  329.                     for (j=0;a[j]!='\0';j++)
  330.                         inbuf[j]=a[j];
  331.                     for (;j<30;j++)
  332.                         inbuf[j]=' ';
  333.                     inbuf[j++]=' ';
  334.                     inbuf[j]='\0';
  335.                     print (inbuf);
  336.                     a=shortdesc[ploc[i]];
  337.                     for (j=0;a[j]!='\0';j++)
  338.                         inbuf[j]=a[j];
  339.                     for (;j<30;j++)
  340.                         inbuf[j]=' ';
  341.                     inbuf[j++]=' ';
  342.                     inbuf[j]='\0';
  343.                     print (inbuf);
  344.                     printshort (strength[i]);
  345.                     writechar ((long)'\n');
  346.                 }
  347.             break;
  348.         case (27):    /* Become */
  349.             if (Noun==0)
  350.                 ploc[0]=ploc[player];
  351.             if (ploc[Noun]==NOWHERE)
  352.             {
  353.                 print ("That person is dead!\n");
  354.                 return (1);
  355.             }
  356.             player=Noun;
  357.             print ("You are ");
  358.             print (pname[player]);
  359.             print (".\n");
  360.             break;
  361.         case (28):    /* Local */
  362.             narration=0;
  363.             print ("Local narration only.\n");
  364.             break;
  365.         case (29):    /* Global */
  366.             narration=1;
  367.             print ("Global narration.\n");
  368.             break;
  369.         case (30):    /* Brief */
  370.             descriptions=0;
  371.             print ("Brief descriptions only.\n");
  372.             break;
  373.         case (31):    /* Normal */
  374.             descriptions=1;
  375.             print ("Long descriptions only in unvisited rooms.\n");
  376.             break;
  377.         case (32):    /* Verbose */
  378.             descriptions=2;
  379.             print ("Long descriptions all the time.\n");
  380.             break;
  381.         case (33):    /* Tame */
  382.             violence=0;
  383.             print ("Tame deaths only.\n");
  384.             break;
  385.         case (34):    /* Gruesome */
  386.             violence=1;
  387.             print ("Gruesome deaths selected.\n");
  388.             break;
  389.         case (35):    /* Exits */
  390.             j=0;
  391.             print ("You can go:\n");
  392.             for (i=0;i<=9;i++)
  393.                 if (exits[ploc[player]][i]>0)
  394.                 {
  395.                     print (directions[i]);
  396.                     j=1;
  397.                 }
  398.             if (j==0)
  399.                 print ("nowhere...\n");
  400.             break;
  401.         case (36):    /* Talk */
  402.             if (talking==0)
  403.                 if (openmouth ())
  404.                 {
  405.                     talkerror ();
  406.                     return (1);
  407.                 }
  408.             talking=1;
  409.             print ("Speech on.\n");
  410.             break;
  411.         case (37):    /* Quiet */
  412.             if (talking==1)
  413.             {
  414.                 talking=2;
  415.                 print ("Speech off.\n");
  416.             }
  417.                 else
  418.                     alreadyquiet ();
  419.             break;
  420.         default:    /* 38=Help */
  421.             print ("These are the verbs I understand:\n");
  422.             for (i=1;i<=VERBS;i++)
  423.             {
  424.                 print (verb[i]);
  425.                 if (i<VERBS)
  426.                     writechar ((long)',');
  427.             }
  428.             print (".\n");
  429.     }
  430.     return (0);        /* Input understood and acted on */
  431. }
  432.  
  433. domobile (p)
  434. int p;
  435. {
  436.     register int i;
  437.     int l,carried,numcarr,j,target;
  438.     int pmaxpower,pmostpower;    /* Most powerful offensive weapons carried */
  439.     int pminpower,pleastpower;    /* Least powerful */
  440.     int lmaxpower,lmostpower;    /* Most powerful in room */
  441.     int lmaxdef,lmostdef;        /* Most powerful defensive weapons */
  442.     int pmaxval,pmostval;        /* Most valuable thing carried */
  443.     int pminval,pleastval;        /* Least valuable */
  444.     int lmaxval,lmostval;        /* Most valuable in room */
  445.     carried=-p;
  446.     l=ploc[p];
  447.     numcarr=numobj (carried);
  448.  
  449.             /* Get more powerful offensive weapon? */
  450.  
  451.     pmaxpower=lmaxpower=40;
  452.     for (i=0;i<AWEAPONS;i++)
  453.     {
  454.         if (oloc[i+FAWEAPON]==carried && attval[i]>pmaxpower)
  455.         {
  456.             pmaxpower=attval[i];
  457.             pmostpower=i;
  458.         }
  459.         if (oloc[i+FAWEAPON]==l && attval[i]>lmaxpower)
  460.         {
  461.             lmaxpower=attval[i];
  462.             lmostpower=i;
  463.         }
  464.     }
  465.     if (lmaxpower>pmaxpower && numcarr<MAXCARR)
  466.     {
  467.         get (p,lmostpower+FAWEAPON);
  468.         return;
  469.     }
  470.  
  471.             /* Get defensive weapon? */
  472.  
  473.     lmaxdef=0;
  474.     for (i=0;i<DWEAPONS;i++)
  475.         if (oloc[i+FDWEAPON]==l && defval[i]>lmaxdef)
  476.         {
  477.             lmaxdef=defval[i];
  478.             lmostdef=i;
  479.         }
  480.     if (lmaxdef && numcarr<MAXCARR)
  481.     {
  482.         get (p,lmostdef+FDWEAPON);
  483.         return;
  484.     }
  485.  
  486.             /* Fight? */
  487.  
  488.     target=0;
  489.     for (i=PLAYERS;i>0;i--)
  490.         if (ploc[i]==l && i!=p)
  491.             target=i;
  492.     if (target)
  493.     {
  494.         if (narration && l!=ploc[player])
  495.         {
  496.             writechar (27L);
  497.             nprint ("[32m");
  498.         }
  499.         if (narration || l==ploc[player])
  500.         {
  501.             print (pname[p]);
  502.             print (" attacks ");
  503.             if (target!=player)
  504.                 print (pname[target]);
  505.                     else
  506.                         print ("you");
  507.             if (pmaxpower>40)
  508.             {
  509.                 print (" with ");
  510.                 oprint (pmostpower+FAWEAPON,0);
  511.             }
  512.             print (".\n");
  513.         }
  514.         for (i=0;i<DWEAPONS;i++)
  515.             if (oloc[i+FDWEAPON]==-target)
  516.                 pmaxpower-=defval[i];
  517.         strength[target]-=pmaxpower;
  518.         if (strength[target]<1)
  519.         {
  520.             ploc[target]=NOWHERE;
  521.             power[p]+=(power[target]/4);
  522.             if ((narration || l==ploc[player])&& target!=player)
  523.             {
  524.                 print (pname[target]);
  525.                 print (" dies.\n");
  526.             }
  527.             if (target==player)
  528.             {
  529.                 print ("You die.\n");
  530.                 gameover=1;
  531.             }
  532.             for (i=1;i<=OBJECTS;i++)
  533.                 if (oloc[i]==-target)
  534.                 {
  535.                     oloc[i]=l;
  536.                     if (l==ploc[player])
  537.                     {
  538.                         oprint (i,1);
  539.                         print (" falls to the ground.\n");
  540.                     }
  541.                 }
  542.         }
  543.         writechar (27L);
  544.         nprint ("[0m");
  545.         return;
  546.     }
  547.  
  548.             /* Drop treasure? */
  549.  
  550.     if (l==DROPZONE)
  551.     {
  552.         pmaxval=0;
  553.         for (i=0;i<TREASURES;i++)
  554.             if (oloc[i+FTREASURE]==carried && value[i]>pmaxval)
  555.             {
  556.                 pmaxval=value[i];
  557.                 pmostval=i;
  558.             }
  559.         if (pmaxval)
  560.         {
  561.             drop (p,pmostval+FTREASURE);
  562.             return;
  563.         }
  564.     }
  565.  
  566.             /* Drop excess weight? */
  567.  
  568.     if (numcarr>=MAXCARR)
  569.     {
  570.         pminpower=9999;
  571.         for (i=0;i<AWEAPONS;i++)
  572.             if (attval[i]<pminpower && oloc[i+FAWEAPON]==carried)
  573.             {
  574.                 pminpower=attval[i];
  575.                 pleastpower=i;
  576.             }
  577.         if (pminpower<pmaxpower)
  578.         {
  579.             drop (p,pleastpower+FAWEAPON);
  580.             return;
  581.         }
  582.         pminval=32767;
  583.         for (i=0;i<TREASURES;i++)
  584.             if (value[i]<pminval && oloc[i+FTREASURE]==carried)
  585.             {
  586.                 pminval=value[i];
  587.                 pleastval=i;
  588.             }
  589.         if (pminval<32767)
  590.         {
  591.             drop (p,pleastval+FTREASURE);
  592.             return;
  593.         }
  594.     }
  595.  
  596.             /* Get keys? */
  597.  
  598.     if (oloc[1]==l && numcarr<MAXCARR)
  599.     {
  600.         get (p,1);
  601.         return;
  602.     }
  603.  
  604.             /* Get treasure? */
  605.  
  606.     lmaxval=0;
  607.     pminval=32767;
  608.     for (i=0;i<TREASURES;i++)
  609.     {
  610.         if (oloc[i+FTREASURE]==l && value[i]>lmaxval)
  611.         {
  612.             lmaxval=value[i];
  613.             lmostval=i;
  614.         }
  615.         if (oloc[i+FTREASURE]==carried && value[i]<pminval)
  616.         {
  617.             pminval=value[i];
  618.             pleastval=i;
  619.         }
  620.     }
  621.     if (lmaxval && (((numcarr+1)<MAXCARR) || (numcarr<MAXCARR && pminval<lmaxval)))
  622.     {
  623.         get (p,lmostval+FTREASURE);
  624.         return;
  625.     }
  626.  
  627.             /* Open door? */
  628.  
  629.     if (strength[p]==power[p] && oloc[1]==carried)
  630.     {
  631.         for (i=0;i<=9;i++)
  632.             if (exits[l][i]<0)
  633.             {
  634.                 exits[l][i]=-exits[l][i];
  635.                 for (j=0;j<=9;j++)
  636.                     if (exits[exits[l][i]][j]==-l)
  637.                         exits[exits[l][i]][j]=l;
  638.                 if (l==ploc[player])
  639.                 {
  640.                     print (pname[p]);
  641.                     print (" opens a door leading ");
  642.                     print (directions[i]);
  643.                 }
  644.                 return;
  645.             }
  646.     }
  647.  
  648.             /* Walk in a random direction */
  649.  
  650.     i=rnd (10);
  651.     (void)walk (p,i);
  652. }
  653.